﻿using System.Globalization;
using UnityEngine;
using UnityEngine.UI;

namespace Assets.Scripts.UI.Panel
{
    public class ExamReslutPanel:UIBase<ExamReslutPanel>
    {
        public Text ObjScoreText;//可观题得分
        public Text SubScoreText;//主观题得分
        public Text SubUnknowScoreText;//主观题为批改的分数
        public Text TotalScoreText;//总分
        public Button SureButton;//确定按钮

        private bool isExam;//是否是考试

        protected override UIType UIType
        {
            get { return UIType.Panel;}
        }

        protected override void InitOnAwake()
        {
            AutoFindComponent(transform,true);
            SureButton.onClick.AddListener(OnSureButtonClick);
#if BEHIND_GRADE
            ObjScoreText.gameObject.SetActive(false);
            SubScoreText.gameObject.SetActive(false);
            SubUnknowScoreText.gameObject.SetActive(false);
            TotalScoreText.gameObject.SetActive(false);
            foreach (Transform item in transform)
            {
                if (item.name.Equals("Label"))
                {
                    item.gameObject.SetActive(false);
                }
            }
            transform.Find("Base/Background").gameObject.SetActive(false);
            SureButton.transform.localPosition = Vector3.zero;
#endif
        }

        private void OnSureButtonClick()
        {
            Exit(2);
            if (isExam)
            {
                CreatePanel(PanelType.MainPanel);
            }
        }

        public void Init(float objScore, float subScore, float subUnKonw, float totalScore,ExamType examType)
        {
            ObjScoreText.text = objScore.ToString(CultureInfo.InvariantCulture);
            SubScoreText.text = subScore.ToString(CultureInfo.InvariantCulture);
            SubUnknowScoreText.text = subUnKonw.ToString(CultureInfo.InvariantCulture);
            TotalScoreText.text = totalScore.ToString(CultureInfo.InvariantCulture);
            if (examType == ExamType.Exam) isExam = true;
        }       
    }
}